package com.mentaleye.controller;

import com.alibaba.fastjson.JSONObject;
import com.mentaleye.biz.DictionaryBiz;
import com.mentaleye.biz.PromptBiz;
import com.mentaleye.enums.DictionaryEnums;
import com.mentaleye.util.CommonPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/prompt")
public class PromptController {

	@Autowired
	PromptBiz promptBiz;
	@Autowired
	DictionaryBiz dictionary;

	@RequestMapping("/promptPage")
	public ModelAndView list() {
		ModelAndView view = new ModelAndView("ss/prompt/promptPage");
		view.addObject("PromptMap", JSONObject.toJSONString(dictionary.queryDictionaryByParent(DictionaryEnums.PROMPT_TPYE.getCode())));
		List<Map<String, Object>> listMap = promptBiz.getCount();
		int ids=151;
		String tableName="jieDuanKaoHe";
		String maths="";
		view.addObject("ids",ids);
		view.addObject("indexTable",JSONObject.toJSONString(tableName));
		view.addObject("mathsTabel",JSONObject.toJSONString(maths));
		view.addObject("countList", listMap);
		return view;
	}
    @RequestMapping("/promptPages")
    public ModelAndView listData(@RequestParam(value ="ids" , required = false)Integer ids,@RequestParam(value = "maths",required = false)String maths,@RequestParam(value = "tableName",required = false)String tableName) {
        ModelAndView view = new ModelAndView("ss/prompt/promptPage");
        view.addObject("PromptMap", JSONObject.toJSONString(dictionary.queryDictionaryByParent(DictionaryEnums.PROMPT_TPYE.getCode())));
        List<Map<String, Object>> listMap = promptBiz.getCount();
        view.addObject("ids",ids);
		view.addObject("indexTable",JSONObject.toJSONString(tableName));
		view.addObject("mathsTabel",JSONObject.toJSONString(maths));
        view.addObject("countList", listMap);
        return view;
    }

	@RequestMapping("/promptPageData")
	@ResponseBody
	public String promptPageData(CommonPage commonPage) {
		promptBiz.getPromptByType(commonPage);
		System.out.println(commonPage.toSHowPage());
		return commonPage.toSHowPage();
	}

	@RequestMapping("/addRead")
	public @ResponseBody String addRead(@RequestParam(value = "promptId", required = false) Integer id/*,
			@RequestParam(value = "promptDetailUrl", required = false) String promptDetailUrl,
			@RequestParam(value = "promptType", required = false) Integer promptType*/) {
		
		//阶段考核URL
		/*int stage = CommonStatus.STAGE_ASSESSMENT.getCode();
		int employment = CommonStatus.EMPLOYMENT_REMINDER.getCode();//就业提醒
		if(promptType==stage){
			ModelAndView view = new ModelAndView("lm/dormitory/dormitoryList");
			view.addObject("enumMap", JSONObject.toJSONString(CommonStatus.enumMap));
			return view;
		}else if(promptType==employment){
			ModelAndView view = new ModelAndView("ss/role/roleList");
			//view.addObject("roles", roleBiz.getAllRole());
			return view;
		}*/
		return JSONObject.toJSONString(promptBiz.updateReadStatus(id));
	}
	
	@RequestMapping("/updateRead")
	public @ResponseBody String updateRead(@RequestParam(value = "checked", required = false) int[] ids,@RequestParam(value = "status", required = false) String status) {
		List<Integer> list = new ArrayList<Integer>();
		for (Integer integer : ids) {
			list.add(integer);
		}
		return JSONObject.toJSONString(promptBiz.updateRead(list, status));
	}

}